#include <iostream>
#include <stack>
#include <string>

bool checkBracketsSequence(std::string sequence) {
    std::stack<char> stack;
    std::unordered_map<char, char> brackets = {{')', '('}, {']', '['}, {'}', '{'}, {'>', '<'}};

    for (char bracket : sequence) {
        if (brackets.find(bracket) != brackets.end()) {
            stack.push(bracket);
        } else if (brackets.find(bracket) != brackets.end()) {
            if (stack.empty() || brackets[bracket] != stack.top()) {
                return false;
            } else {
